import request from './request'

/**
 * 健康数据分析API
 */
export const healthAnalyticsApi = {
  /**
   * 生成健康分析
   * @param {number} userId - 用户ID
   * @param {string} analysisType - 分析类型
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  generateAnalysis(userId, analysisType, startDate, endDate) {
    return request({
      url: '/api/health-analytics/generate',
      method: 'post',
      data: {
        userId,
        analysisType,
        startDate,
        endDate
      }
    })
  },

  /**
   * 生成生命体征分析
   * @param {number} userId - 用户ID
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  generateVitalSignsAnalysis(userId, startDate, endDate) {
    return request({
      url: '/api/health-analytics/vital-signs',
      method: 'post',
      data: {
        userId,
        startDate,
        endDate
      }
    })
  },

  /**
   * 生成健康趋势分析
   * @param {number} userId - 用户ID
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  generateHealthTrendAnalysis(userId, startDate, endDate) {
    return request({
      url: '/api/health-analytics/health-trend',
      method: 'post',
      data: {
        userId,
        startDate,
        endDate
      }
    })
  },

  /**
   * 生成风险评估
   * @param {number} userId - 用户ID
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  generateRiskAssessment(userId, startDate, endDate) {
    return request({
      url: '/api/health-analytics/risk-assessment',
      method: 'post',
      data: {
        userId,
        startDate,
        endDate
      }
    })
  },

  /**
   * 生成症状模式分析
   * @param {number} userId - 用户ID
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  generateSymptomPatternAnalysis(userId, startDate, endDate) {
    return request({
      url: '/api/health-analytics/symptom-pattern',
      method: 'post',
      data: {
        userId,
        startDate,
        endDate
      }
    })
  },

  /**
   * 获取用户分析记录（分页）
   * @param {number} userId - 用户ID
   * @param {number} pageNum - 页码
   * @param {number} pageSize - 页大小
   */
  getUserAnalytics(userId, pageNum = 1, pageSize = 10) {
    return request({
      url: `/api/health-analytics/user/${userId}`,
      method: 'get',
      params: {
        pageNum,
        pageSize
      }
    })
  },

  /**
   * 按类型获取分析记录
   * @param {number} userId - 用户ID
   * @param {string} analysisType - 分析类型
   */
  getAnalyticsByType(userId, analysisType) {
    return request({
      url: `/api/health-analytics/user/${userId}/type/${analysisType}`,
      method: 'get'
    })
  },

  /**
   * 获取最近分析记录
   * @param {number} userId - 用户ID
   * @param {number} limit - 记录数量
   */
  getRecentAnalytics(userId, limit = 5) {
    return request({
      url: `/api/health-analytics/user/${userId}/recent`,
      method: 'get',
      params: {
        limit
      }
    })
  },

  /**
   * 获取健康评分趋势
   * @param {number} userId - 用户ID
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  getHealthScoreTrend(userId, startDate, endDate) {
    return request({
      url: `/api/health-analytics/user/${userId}/health-score-trend`,
      method: 'get',
      params: {
        startDate,
        endDate
      }
    })
  },

  /**
   * 获取健康统计数据
   * @param {number} userId - 用户ID
   */
  getHealthStatistics(userId) {
    return request({
      url: `/api/health-analytics/user/${userId}/statistics`,
      method: 'get'
    })
  },

  /**
   * 获取未读高风险分析
   * @param {number} userId - 用户ID
   */
  getUnreadHighRiskAnalytics(userId) {
    return request({
      url: `/api/health-analytics/user/${userId}/unread-high-risk`,
      method: 'get'
    })
  },

  /**
   * 标记为已读
   * @param {number} analyticsId - 分析ID
   */
  markAsRead(analyticsId) {
    return request({
      url: `/api/health-analytics/${analyticsId}/mark-read`,
      method: 'put'
    })
  },

  /**
   * 批量标记为已读
   * @param {Array<number>} analyticsIds - 分析ID列表
   */
  batchMarkAsRead(analyticsIds) {
    return request({
      url: '/api/health-analytics/batch-mark-read',
      method: 'put',
      data: analyticsIds
    })
  },

  /**
   * 删除分析记录
   * @param {number} analyticsId - 分析ID
   * @param {number} userId - 用户ID
   */
  deleteAnalytics(analyticsId, userId) {
    return request({
      url: `/api/health-analytics/${analyticsId}`,
      method: 'delete',
      params: {
        userId
      }
    })
  },

  /**
   * 获取各类型最新分析
   * @param {number} userId - 用户ID
   */
  getLatestAnalyticsByType(userId) {
    return request({
      url: `/api/health-analytics/user/${userId}/latest-by-type`,
      method: 'get'
    })
  },

  /**
   * 获取月度汇总
   * @param {number} userId - 用户ID
   * @param {number} year - 年份
   * @param {number} month - 月份
   */
  getMonthlySummary(userId, year, month) {
    return request({
      url: `/api/health-analytics/user/${userId}/monthly-summary`,
      method: 'get',
      params: {
        year,
        month
      }
    })
  },

  /**
   * 获取改善趋势
   * @param {number} userId - 用户ID
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  getImprovementTrend(userId, startDate, endDate) {
    return request({
      url: `/api/health-analytics/user/${userId}/improvement-trend`,
      method: 'get',
      params: {
        startDate,
        endDate
      }
    })
  },

  /**
   * 计算健康评分
   * @param {number} userId - 用户ID
   * @param {string} startDate - 开始日期
   * @param {string} endDate - 结束日期
   */
  calculateHealthScore(userId, startDate, endDate) {
    return request({
      url: '/api/health-analytics/calculate-health-score',
      method: 'post',
      data: {
        userId,
        startDate,
        endDate
      }
    })
  },

  /**
   * 获取系统健康统计
   */
  getSystemHealthStats() {
    return request({
      url: '/api/health-analytics/system/stats',
      method: 'get'
    })
  },

  /**
   * 清理过期记录
   * @param {number} daysToKeep - 保留天数
   */
  cleanupExpiredRecords(daysToKeep = 90) {
    return request({
      url: '/api/health-analytics/cleanup',
      method: 'delete',
      params: {
        daysToKeep
      }
    })
  }
}

export default healthAnalyticsApi